﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ObjectDirectory;

namespace t_ObjectDirectory
{
    [TestClass]
    public class t_ObjectPathManager
    {
        class EmptyObject
        {
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestGetPathNullRoot()
        {
            ObjectPathManager mgr = new ObjectPathManager();
            mgr.GetPath(null, null);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestGetPathNullLeaf()
        {
            ObjectPathManager mgr = new ObjectPathManager();
            EmptyObject b = new EmptyObject();
            mgr.GetPath(b, null);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestFindObjectNullRoot()
        {
            ObjectPathManager mgr = new ObjectPathManager();
            mgr.GetPath(null, ".");
        }

        [TestMethod]
        public void TestSimpleObject()
        {
            EmptyObject b = new EmptyObject();
            ObjectPathManager mgr = new ObjectPathManager();
            Assert.AreEqual(".", mgr.GetPath(b, b), "The relative path for an object that is itself was not null");

            Assert.AreEqual(b, mgr.FindObjectFromPath(b, ""), "Unable to return same object when path is empty string");
            Assert.AreEqual(b, mgr.FindObjectFromPath(b, null), "Unable to return same object when path is null");
            Assert.AreEqual(b, mgr.FindObjectFromPath(b, "."), "Unable to return same object when path is a period");
        }
    }
}